package com.baomidou.mybatisplus.criterion;

/**
 * Constrains the property to a specified list of values
 * @author Timothy Ren
 */
public class InExpression implements QueryCriterion {

	private static final long serialVersionUID = 1L;
	private final String propertyName;
	private final Object[] values;

	protected InExpression(String propertyName, Object[] values) {
		this.propertyName = propertyName;
		this.values = values;
	}

	public String toSqlString() {
		String params;
		if (values.length > 0) {
			params = StringHelper.repeat("?, ", values.length - 1);
			params += "?";
		} else {
			params = "";
		}
		StringBuffer sb = new StringBuffer(propertyName).append(" in (").append(params).append(")");
		return sb.toString();
	}

	public Object[] getValueArr() {
		return values;
	}

	public String toString() {
		return propertyName + " in (" + StringHelper.toString(values) + ')';
	}

}
